﻿package pluginfw.nio.message
{
    import flash.utils.*;

    public class ProxyMessage extends Object implements IProxyMessage
    {
        protected var buffer:ByteArray;
        protected var obj:Object;
        protected var property:String;

        public function ProxyMessage()
        {
            this.buffer = new ByteArray();
            return;
        }// end function

        public function getSize() : int
        {
            this.buffer.position = 0;
            return this.buffer.readInt();
        }// end function

        public function getMessageId() : int
        {
            this.buffer.position = 5;
            return this.buffer.readShort();
        }// end function

        public function getCrc() : int
        {
            this.buffer.position = 7;
            return this.buffer.readShort();
        }// end function

        public function getType() : int
        {
            return 1;
        }// end function

        public function getBuffer() : ByteArray
        {
            this.buffer.position = 0;
            return this.buffer;
        }// end function

        public function getObject() : Object
        {
            if (this.obj == null && this.buffer.length > 45)
            {
                this.buffer.position = 45;
                this.obj = this.buffer.readObject();
            }
            return this.obj;
        }// end function

        public function getProperty() : String
        {
            if (this.property == null)
            {
                this.buffer.position = 13;
                this.property = this.buffer.readUTFBytes(32);
            }
            return this.property;
        }// end function

        public function getProxyId() : int
        {
            this.buffer.position = 9;
            return this.buffer.readInt();
        }// end function

    }
}
